//
//  KBbsTopicView.m
//  Keping
//
//  Created by a on 2017/9/27.
//  Copyright © 2017年 柯平. All rights reserved.
//

#import "KBbsTopicView.h"
#import "NSString+KSize.h"

@implementation KBbsTopicView

-(BOOL)modelCustomTransformFromDictionary:(NSDictionary*)dic {
    _summaryHeight = [NSString sizeWithString:[dic objectForKey:@"summary"] Size:CGSizeMake(kScreenWidth - 30, MAXFLOAT) Font:17].height;
    return YES;
}
@end


@implementation KBbsPostsViews

-(BOOL)modelCustomTransformFromDictionary:(NSDictionary*)dic {
    id commont = [dic objectForKey:@"commontQty"];
    if ([commont isKindOfClass:[NSNull class]]) {
        _commontQty = @"0 Comments";
    } else {
        _commontQty = [NSString stringWithFormat:@"%@ Comments",commont];
    }
    _content = [dic objectForKey:@"content"];
    _toRealName = [dic objectForKey:@"toRealName"];
    _realName = [dic objectForKey:@"realName"];
    NSString *comment;
    if (_toRealName) {
        comment = [NSString stringWithFormat:@"%@ Reply %@: %@",_realName,_toRealName,_content];
    } else {
        comment = [NSString stringWithFormat:@"%@: %@",_realName,_content];
    }
    _contentHeight = [self sizeWithBBSString:comment].height;
    _cellHeight = 15 + 17 + 10 + _contentHeight + 17 + 13 + 20;
    _countWidth = [self sizeWithBBSString:_commontQty].width;
    
    return YES;
}

- (CGSize)sizeWithBBSString:(NSString *)text
{
    // 12:图标距离左边距离,40:图片宽度, 15:用户名距离图片左距离,20:用户名距离右距离
    CGFloat margin = K_FactorW(kScreenWidth - (12 + 40 + 15 + 20));
    CGSize frame = [text boundingRectWithSize:CGSizeMake(margin, MAXFLOAT)
                                      options:NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin
                                   attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17]}
                                      context:nil].size;
    return frame;
}

@end
